package com.shut.vehicle.task;

import com.shut.vehicle.pojo.ServiceRecord;
import com.shut.vehicle.service.BookingRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

/**
 * @author 卢斌
 */
@Component
public class ApplicationFinishStartTask implements CommandLineRunner {

    @Autowired
    private BookingRecordService bookingRecordService;

    @Override
    public void run(String... args) throws Exception {
        LocalDateTime localDateTime = LocalDateTime.now();
        localDateTime = localDateTime.plusHours(-48);
        ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
        Date date = Date.from(zdt.toInstant());
        bookingRecordService.cleanUnFinishedService(date);
        bookingRecordService.bufferAllUnfinishedService();
    }
}
